<?php

/**
 * to use this method, please signup a captcha private key & public key at https://www.google.com/recaptcha
 * @see https://www.google.com/recaptcha
 *
 */
class Html_Element_Captcha extends Html_Element_Field
{
	protected $_name = 'captcha';

	protected $_rules = array();

	protected $_meta = array(
		'label' => 'Captcha',
		'render' => 'captcha',
		'adapter' => 'recaptcha',
	);

	protected $_attrib = array(
		'type' => 'text',
		'class' => 'text email',
		'type' => 'text',
		'name' => 'email',
	);

	public function _isValid($value)
	{
		$valid = true;

		$adapter = $this -> getMeta('adapter');

		$class_name = 'Rule_Captcha_' . ucfirst($adapter);

		$object = new $class_name();

		if (!$object -> isValid($value))
		{
			$this -> addError($object -> getMsg());
			$valid = false;
		}

		return $valid;
	}

}
